// 获取所有城市并添加到页面
$.getJSON("address.json",function(data){
    var citys;
    $.each(data,function(k,p){
        citys = p.name;
        var li = "<li>"+citys+"</li>";
        $(".section_box .sec_left .con_city .city_list").append(li);
    })
    //点击当前城市时背景和文字颜色发生改变
    $(".city_list li").click(function(){
        $(".city_list li").css("background","#fff");
        $(".city_list li").css("color","#000");
        $(this).css("background","#ed0a75");
        $(this).css("color","#fff");
     })  
})
// .section_list .list_top ul li
$(".section_list .list_top ul li").click(function(){
    $(".section_list .list_top ul li").css("color","#000");
    $(".section_list .list_top ul li").css("background","#f5f5f5");
    $(this).css("background","#fff");
    $(this).css("color","#ed0a75");
})



// 获取栏目列表并添加
$.ajax({
    url:"http://47.99.153.121:8021/index.php/index/types",
    dataType:"json",
    success:function(res){
        $.each(res,function(k,p){
        	// console.log(p)
            var column = p.cname;
            var li = "<li>"+column+"</li>";
            $("._column").append(li);
        })
        $("._column li").click(function(){
            $("._column li").css("background","#fff");
            $("._column li").css("color","#000");
            $(this).css("background","#ed0a75");
            $(this).css("color","#fff");
         })  
    }
})
$("._times li").click(function(){
    $("._times li").css("background","#fff");
    $("._times li").css("color","#000");
    $(this).css("background","#ed0a75");
    $(this).css("color","#fff");
 }) 


//点击更多和收起时发生的事件
$(".section_box .sec_left .con_city .more").click(function(){
    $(".section_box .sec_left .city_list").css("height","496");
    $(".section_box .sec_left .con_city .more").css("display","none");
    $(".section_box .sec_left .con_city .retract").css("display","block");
});
$(".section_box .sec_left .con_city .retract").click(function(){
    $(".section_box .sec_left .city_list").css("height","62");
    $(".section_box .sec_left .con_city .more").css("display","block");
    $(".section_box .sec_left .con_city .retract").css("display","none");
});


//点击切换列表排列
$(".list_line").click(function(){
    $(".list_line").addClass("list_line_on");
    $(".list_line").removeClass("list_line");
    $(".list_column_on").addClass("list_column");
    $(".list_column_on").removeClass("list_column_on");
    $(".line").css("display","block");
    $(".column").css("display","none");
    
})
$("#listClm").click(function(){
    $("#listClm").addClass("list_column_on");
    $("#listClm").removeClass("list_column");
    $("#listLin").addClass("list_line");
    $("#listLin").removeClass("list_line_on");
    $(".line").css("display","none");
    $(".column").css("display","block");
})

//接收传过来的参数cid
var getcid = location.href;
console.log(getcid)
var newcid = getcid.split("?")[1];
var arr = newcid.split("=")[1];
var arr1 = parseInt(arr);
// console.log(arr1)


//搜索框
var arr0 = newcid.split("=")[0]; 
console.log(arr0)//keyword
if(arr0 == "keyword"){
    id = decodeURI(arr);//中文解码
    console.log(id)//费玉清
    var url="http://www.web520.xyz/web-projectAPI/index.php/index/search?keyword="+id;
	console.log(url);
    getMy1(url);
    getMy2(url);  
}else{
    url="http://47.99.153.121:8021/index.php/index/details/typeId/"+arr1;
    getMy1(url);
    getMy2(url);
}
//分页面的搜索框

//列排列时
function getMy1(url) {
    $.ajax({
        url:url,
        dataType:"json",
        type:"get",
        success:function (res) {
            $.each(res,function (k,p) {
                var img = p.profermer_photo;
                var title = p.title;
                var city = p.city;
                var time = (p.releasetime)
                var address = p.address;
                var price = p.price;
                var id = p.cid;//ID 
                var li = ` <li>
                <div class='img' onclick="window.location.href='barley0.html?did=${p.did}'"><img src="${img}"></div>
                <div class="text"><h3>【${city}】<a href="barley0.html?did=${p.did}">${title}</a></h3>
                <p class="text_time"><a class="time_ico"></a>${time}</p>
                <p class="text_address"><a class="time_ico time_icoAd">${address}</a></p>
                <p class="text_price"><em>${price}</em>售票中</p></div>
                </li>`;
                $(".column").append(li);
            })
        }
    })
}
// getMy1(url);

//横向排列时
function getMy2(url) {
    $.ajax({
        url:url,
        dataType:"json",
        type:"get",
        success:function (res) {
            $.each(res,function(k,p){
                var img = p.profermer_photo;
                var title = p.title;
                var city = p.city;
                var time = (p.releasetime)
                var address = p.address;
                var price = p.price;
                var id = p.cid;//ID 
                var li = ` <li><img src="${img}">
                <div class="text">【${city}】<a href="">${title}</a>
                <p class="time">${time}</p>
                <p class="price"><em>${price}</em>售票中</p></div>
                </li>`;
                $(".line").append(li);
                
            })
        }
    })
}
// getMy2(url);


	//回到顶部
	$(window).scroll(function(){
		var offsetHeight = document.documentElement.offsetHeight;
		// console.log(offsetHeight)
		var clientHeight = document.documentElement.clientHeight;
		// console.log(clientHeight)
		var scrollTop = document.documentElement.scrollTop;
		// console.log(scrollTop)
		// var scrollBottom = offsetHeight - clientHeight - scrollTop;
		// console.log(scrollBottom)
		if(scrollTop>80){
			$(".sidebar .go-top").show();
			$(".sidebar .go-top").click(function(){
				scrollTo(0,0);
			})
		}else{
			$(".sidebar .go-top").hide();
		}
	})